package com.cs171.market.mapper;

import com.cs171.market.entity.Catogery;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Endy
 * @create 2020 - 06 - 20 - 13:08
 * @date 2020/6/20 - 13:08
 */

@Mapper
public interface CategoryMapper {
    @Select("Select cat_id, cat_name, cat_pid, cat_deleted, cat_level FROM sp_category")
    List<Catogery> findAllCategory();

    @Select("Select cat_id, cat_name, cat_pid, cat_deleted, cat_level  FROM sp_category")
    Page<Catogery> findPageCategory();

    @Select("Insert INTO sp_category (cat_pid, cat_name, cat_level, cat_deleted) VALUES (#{cat_pid}, #{cat_name}, #{cat_level}, 0)")
    void addCategory(Integer cat_pid, String cat_name, Integer cat_level);

    @Select("Select cat_id, cat_name, cat_pid, cat_level FROM sp_category WHERE cat_id = (Select MAX(cat_id) FROM sp_category)")
    Catogery responseAdd();

    @Select("Select cat_id, cat_name, cat_pid, cat_level FROM sp_category WHERE cat_id = #{id}")
    Catogery findCategoryById(Integer id);

    @Select("Update sp_category SET cat_name = #{name} WHERE cat_id = #{id}")
    void setCategory(Integer id, String name);

    @Select("Delete FROM sp_category WHERE cat_id=#{id}")
    void deleteCategory(Integer id);
}
